package com.ng.desktop.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.IndexColumn;

/**
 * @author psabbate
 * 
 */
@Entity
@Table(name = "TH_RECETA")
public class Receta {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID", nullable = false)
	private Long id;

	@Column(name = "NOMBRE", nullable = false, length = 60)
	private String nombre;

	@Column(name = "DESCRIPCION", nullable = false, length = 1024)
	private String descripcion;

	@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
	@ForeignKey(name = "FK_RECETA", inverseName = "FK_ALIMENTO")
	@JoinTable(name = "TH_RECETA_ALIMENTO", joinColumns = @JoinColumn(name = "ID_RECETA"), inverseJoinColumns = @JoinColumn(name = "ID_ALIMENTO"))
	@IndexColumn(name = "IDX_RECETA_ALIMENTO")
	private List<Alimento> alimentos;

	public Long getId() {
		return id;
	}

	public String getNombre() {
		return nombre;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public List<Alimento> getAlimentos() {
		return alimentos;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public void setAlimentos(List<Alimento> alimentos) {
		this.alimentos = alimentos;
	}
	
	@Override
	public String toString() {
		return nombre;
	}
}
